home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / src / loaders / Xout / decode.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-03  |  2.5 KB  |  171 lines

  1.     XDEF    _DecodeTrack
  2.  
  3. SYNC_WORD = $8455 
  4.  
  5. GETLONG:MACRO
  6.     movem.l    D3-D4,-(sp)
  7.     move.l    (A2)+,\1    ; higher part (dest register)
  8.     move.l    (A2),D3
  9.     lsr.l    D7,D3        ; shift lower part with count
  10.     moveq    #$20,D4
  11.     sub.l    D7,D4
  12.     lsl.l    D4,\1        ;higher part has to be shifted to fill
  13.     or.l    D3,\1        ;the rest-place, a longword has 20 bits
  14.     movem.l    (sp)+,D3-D4    
  15.     ENDM
  16.  
  17.  
  18. asmtest:
  19.     move.l    #dectrack,A0
  20.     move.l    #rawtrack,D0
  21.     bsr    DecodeTrack
  22.     rts
  23.  
  24. ; *** finds sync and shift
  25.  
  26. ; in A0 rawdata
  27. ; out: D0 = 0 if success
  28. ;      D1 = shift (0-15)
  29.  
  30. GetSync:
  31.     movem.l    D2-D6/A1-A6,-(sp)
  32.  
  33.     MOVE.L    A0,A2
  34.     lea    $7C00(A2),A4        ;end of rawtrack
  35.  
  36. .SHF2    MOVEQ.L    #$10-1,D5
  37.  
  38.     ; *** try to find the sync shift (0 to 15)
  39.  
  40. .SHF1    MOVE.L    (A2),D0        ; a longword of data
  41.     LSR.L    D5,D0        ; shift it by D5
  42.     CMP.W    #SYNC_WORD,D0    ; sync?
  43.     BEQ.S    .SY        ; yes: found sync AND shift
  44.     DBF    D5,.SHF1
  45.     ADDQ.L    #2,A2
  46.     cmp.l    A2,A4
  47.     beq    ErrorSyn
  48.     BRA.S    .SHF2
  49.  
  50.     ; ** shift has been found, sync too.
  51.  
  52. .SY    MOVE.L    (A2),D0
  53.     ADDQ.L    #2,A2
  54.     LSR.L    D5,D0            ;d5 is the shifting-number when sync was found
  55.     CMP.W    #SYNC_WORD,D0
  56.     BNE.S    .SY
  57.  
  58. .1    MOVE.L    (A2),D0
  59.     ADDQ.L    #2,A2
  60.     LSR.L    D5,D0
  61.     CMP.W    #SYNC_WORD,D0
  62.     BEQ.S    .1
  63.  
  64.     moveq    #0,D0
  65.     move.l    A2,A0    ; buffer synced
  66.     move.l    D5,D1    ; shift
  67.     bra    ExitSyn
  68.  
  69. ErrorSyn:
  70.     moveq    #-1,D0
  71. ExitSyn
  72.     movem.l    (sp)+,D2-D6/A1-A6
  73.     rts
  74.  
  75. _DecodeTrack:
  76.     move.l    4(sp),D0
  77.     move.l    8(sp),A0
  78. DecodeTrack
  79.     movem.l    D1-A6,-(sp)
  80.  
  81.     move.l    A0,A1    ; dec
  82.     move.l    D0,A0    ; raw
  83.  
  84.     lea    $7FFE(A0),A2
  85.  
  86.     bsr    GetSync
  87.     tst.l    D0
  88.     bne    syncerr
  89.  
  90.  
  91.     move.l    D1,D7        ; shift : D7
  92.  
  93.     subq.l    #2,A0        ; longword reader
  94.  
  95. LB_C962
  96.     MOVE.L    (A0),D0        ; read word
  97.     addq.l    #2,A0
  98.     lsr.l    D7,D0        ; shift
  99.  
  100.     CMP.W    #$2AAA,D0
  101.     BNE    decodeerr
  102.  
  103.     subq.l    #2,A0        ; longword reader needs this
  104.  
  105.     move.l    A0,A2
  106.  
  107.     ; *** begin read track
  108.  
  109.     MOVE.L    #$55555555,D3
  110.     GETLONG    D5            ; checksum!!
  111.  
  112. ;    MOVE.L    (A2)+,D5
  113.  
  114.     AND.L    D3,D5            ; checksum
  115.     MOVEQ    #0,D1
  116.     MOVE.L    #$0BA7,D0
  117. decodeloop1
  118.  
  119. ;    MOVE.L    (A2)+,D6
  120.  
  121.     GETLONG    D6
  122.  
  123.     AND.L    D3,D6
  124.     ADD.L    D6,D1
  125.     DBF    D0,decodeloop1
  126.  
  127.     AND.L    D3,D1
  128.     CMP.L    D1,D5
  129.     BNE    decodeerr        ; wrong checksum
  130.  
  131.     MOVE.L    #$05D3,D0        ;1D6: 303C05D3
  132.     LEA    4(A0),A2
  133.  
  134. decodeloop2:
  135.     move.l    A2,-(sp)
  136.     lea    5968(A2),A2
  137.     GETLONG    D1
  138.     move.l    (sp)+,A2
  139.  
  140. ;    MOVE.L    5968(A2),D1        ;1E0: 222A1750
  141.  
  142.     GETLONG    D2
  143.  
  144.     AND.L    D3,D1            ;1E6: C283
  145.     AND.L    D3,D2            ;1E8: C483
  146.     ASL.L    #1,D2            ;1EA: E382
  147.     OR.L    D2,D1            ;1EC: 8282
  148.     MOVE.L    D1,(A1)+        ;1EE: 22C1
  149.     DBF    D0,decodeloop2
  150.  
  151.  
  152.     movem.l    (sp)+,D1-A6
  153.     moveq    #0,D0
  154.     RTS    
  155.  
  156. syncerr:
  157.     movem.l    (sp)+,D1-A6
  158.     moveq    #-2,D0
  159.     rts
  160.  
  161. decodeerr:
  162.     movem.l    (sp)+,D1-A6
  163.     moveq    #-1,D0
  164.     rts
  165.  
  166. dectrack:
  167. ;    blk.b    $1A00,0
  168. rawtrack:
  169. ;    incbin    "xout.raw"
  170.  
  171.